<?php 
namespace Models;
/**
 * 题目模型
 * @package Models
 * @author 江羿平<hugcolin@163.com>
 */
class Question extends Model{

	protected $_table = 'questions';

	protected $_filter = FALSE;

	protected $_primekey = 'id';


	public static function options_display($type,$options,$answer){
		$html = '';
		if($type == 1){
			$options = json_decode($options,true);
			$i = 1;
			foreach ($options as $o) {
				if($answer == $i) $html .= '<div class="text-success glyphicon glyphicon-ok"><span class=""></span>'.$o.'</div>';
				else $html .= '<div class="text-danger"><span class="glyphicon glyphicon-remove"></span>'.$o.'</div>';
				$i++;
			}
		}

		if($type == 2){
			$options = json_decode($options,true);
			$answers = explode(',', $answer);
			$i = 1;
			foreach ($options as $o) {
				if(in_array($i, $answers)) $html .= '<div class="text-success glyphicon glyphicon-ok"><span class=""></span>'.$o.'</div>';
				else $html .= '<div class="text-danger"><span class="glyphicon glyphicon-remove"></span>'.$o.'</div>';
				$i++;
			}
		}

		if($type == 3){
			$answers = json_decode($answer,true);
			foreach ($answers as $a) {
				$html .= '<div>'.$a.'</div>';
			}
		}

		if($type == 4){
			$html .= '<div id="imageChose-div"><img src="'.$options.'" />';
			$answers = json_decode($answer,true);
			foreach ($answers as $a) {
				$html .='<div class="imageChose-item" style="top:'.$a['y'].'px;left:'.$a['x'].'px;width:'.$a['width'].'px;height:'.$a['height'].'px"></div>';
			}
			$html .='</div>';
		}

		if($type == 5){
			$options = json_decode($options,true);
			$answers = explode(',', $answer);
			$i = 0;
			foreach ($options as $o) {
				$html .= '<div>['.$answers[$i].']'.$o.'</div>';
				$i++;
			}
		}
		return $html;

	}


}
?>